<script lang="jsx">
import { defineComponent, h } from "vue";
import { ElInput } from "element-plus";

export default defineComponent({
  name: "cInput",
  inheritAttrs: false, // 禁用 Attributes 继承 (取消v-on监听器的继承)
  props: {
    ...ElInput.props,
  },
  setup(props, e) {
    const { slots, attrs, emit } = e;
    /**
     * 仅当 modelValue 改变时，当输入框失去焦点或用户按Enter时触发
     * */
    function inputChange(value) {
      emit("change", value.trim());
      emit("update:modelValue", value.trim()); // 输入框失去焦点后移除字符左右空格
    }

    return () =>
      h(ElInput, { ...props, ...attrs, onChange: inputChange }, slots);
  },
});
</script>
